package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.entity.Result;
import com.itheima.pojo.Address;
import com.itheima.service.AddressService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/address")
public class AddressController {
    @Reference
    private AddressService addressService;

    @RequestMapping("/findPage")
    public PageResult findPage(@RequestBody QueryPageBean queryPageBean) {
        PageResult pageResult = addressService.pageQuery(queryPageBean);
        return pageResult;
    }
    @RequestMapping("/findAddress")
    public Result findAddress(){
        try {
            List<String> address = addressService.findAddress();
            return new Result(true,"查到数据了",address);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,"查找出错了");
        }
    }
    @RequestMapping("/add")
    public Result addAddress(@RequestBody Address address){
        try {
            addressService.addAddress(address);
            return new Result(true, "添加地址成功");
        } catch (Exception e) {
            e.printStackTrace();
            return  new Result(false, "添加地址失败");
        }
    }

}
